
package dao;

import org.hibernate.Session;
import org.hibernate.Transaction;
import persistencia.HibernateUtil;


public class Dao<T> {

    private Class classe;
    private Session session;

    protected Session getSession() {
        return session;
    }

    public Dao(Class classe) {
        this.session = HibernateUtil.getSession();
        this.classe = classe;
    }

    public void salvar(T objeto){
        session.save(objeto);
    }

    public void remover(T objeto){
        Transaction ts = session.beginTransaction();
        session.delete(objeto);
        ts.commit();
    }

    public void atualizar(T objeto){
    	
        Transaction ts = session.beginTransaction();
        session.update(objeto);
        ts.commit();
    }

    public T load(long id){
        return (T) session.load(classe, id);
    }
}
